/**
 * Copyright 2010 Creative Works, Inc.
 * Creative Works licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package org.sendvox.freswitch.event.impl;

import java.util.Date;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.sendvox.freswitch.event.ChannelCallState;
import org.sendvox.freswitch.event.ChannelState;
import org.sendvox.freswitch.event.Event;

public abstract class ChannelMessage implements Message {

	private static final long serialVersionUID = 8580020611369230786L;

	private Date dateReceived;
	private String coreUUID;
	private String freeSwitchHostname;
	private String freeSwitchSwitchname;
	private String freeSwitchIPv4;
	private String freeSwitchIPv6;
	private String eventDateLocal;
	private String eventDateGMT;
	private String eventDateTimestamp;
	private String eventCallingFile;
	private String eventCallingFunction;
	private Integer eventCallingLineNumber;

	private ChannelState channelState;
	private ChannelCallState channelCallState;
	private Integer channelStateNumber;
	private String channelName;
	private String uniqueID;
	private String callDirection;
	private String presenceCallDirection;
	private String channelPresenceID;
	private String channelCallUUID;
	private ChannelCallState answerState;
	private String channelReadCodecName;
	private Integer channelReadCodecRate;
	private Integer channelReadCodecBitRate;
	private String channelWriteCodecName;
	private Integer channelWriteCodecRate;
	private Integer channelWriteCodecBitRate;
	private String callerDirection;
	private String callerCallerIDNumber;
	private String callerCalleeIDName;
	private String callerCalleeIDNumber;
	private String callerNetworkAddr;
	private String callerDestinationNumber;
	private String callerUniqueID;
	private String callerSource;
	private String callerContext;
	private String callerChannelName;
	private Integer callerProfileIndex;
	private String callerProfileCreatedTime;
	private String callerChannelCreatedTime;
	private String callerChannelAnsweredTime;
	private String callerChannelProgressTime;
	private String callerChannelProgressMediaTime;
	private String callerChannelHangupTime;
	private String callerChannelTransferTime;
	private boolean callerScreenBit;
	private boolean callerPrivacyHideName;
	private boolean callerPrivacyHideNumber;

	public ChannelMessage() {
		super();
		this.dateReceived = new Date();
	}

	/**
	 * The event's name, which is a description of the type of event it is
	 * 
	 * @return eventName
	 */
	public abstract Event getEventName();

	/**
	 * The UUID of the current instance of the FreeSWITCH core
	 * 
	 * @return coreUUID
	 */
	public String getCoreUUID() {
		return coreUUID;
	}

	/**
	 * Sets the UUID of the current instance of the FreeSWITCH core
	 * 
	 * @param coreUUID
	 */
	public void setCoreUUID(String coreUUID) {
		this.coreUUID = coreUUID;
	}

	/**
	 * @return the freeSwitchHostname
	 */
	public String getFreeSwitchHostname() {
		return freeSwitchHostname;
	}

	/**
	 * @param freeSwitchHostname
	 *            the freeSwitchHostname to set
	 */
	public void setFreeSwitchHostname(String freeSwitchHostname) {
		this.freeSwitchHostname = freeSwitchHostname;
	}

	/**
	 * @return the freeSwitchSwitchname
	 */
	public String getFreeSwitchSwitchname() {
		return freeSwitchSwitchname;
	}

	/**
	 * @param freeSwitchSwitchname
	 *            the freeSwitchSwitchname to set
	 */
	public void setFreeSwitchSwitchname(String freeSwitchSwitchname) {
		this.freeSwitchSwitchname = freeSwitchSwitchname;
	}

	/**
	 * The date/time of the event in GMT (that is, UTC) time
	 * 
	 * @return eventDateLocal
	 */
	public String getEventDateLocal() {
		return eventDateLocal;
	}

	/**
	 * Sets the date/time of the event in GMT (that is, UTC) time
	 * 
	 * @param eventDateLocal
	 */
	public void setEventDateLocal(String eventDateLocal) {
		this.eventDateLocal = eventDateLocal;
	}

	/**
	 * The C source file from which the event was fired
	 * 
	 * @return eventCallingFile
	 */
	public String getEventCallingFile() {
		return eventCallingFile;
	}

	/**
	 * Sets the C source file from which the event was fired
	 * 
	 * @param eventCallingFile
	 */
	public void setEventCallingFile(String eventCallingFile) {
		this.eventCallingFile = eventCallingFile;
	}

	/**
	 * The name of the function that fired this event
	 * 
	 * @return eventCallingFunction
	 */
	public String getEventCallingFunction() {
		return eventCallingFunction;
	}

	/**
	 * Sets the name of the function that fired this event
	 * 
	 * @param eventCallingFunction
	 */
	public void setEventCallingFunction(String eventCallingFunction) {
		this.eventCallingFunction = eventCallingFunction;
	}

	/**
	 * The exact line number of the C source file where this event was fired
	 * 
	 * @return eventCallingLineNumber
	 */
	public Integer getEventCallingLineNumber() {
		return eventCallingLineNumber;
	}

	/**
	 * The exact line number of the C source file where this event was fired
	 * 
	 * @param eventCallingLineNumber
	 */
	public void setEventCallingLineNumber(Integer eventCallingLineNumber) {
		this.eventCallingLineNumber = eventCallingLineNumber;
	}

	/**
	 * The date when the event was received by SendVox
	 * 
	 * @return dateReceived
	 */
	public Date getDateReceived() {
		return dateReceived;
	}

	/**
	 * Sets the date when the event was received by SendVox
	 * 
	 * @param dateReceived
	 */
	public void setDateReceived(Date dateReceived) {
		this.dateReceived = dateReceived;
	}

	/**
	 * By default this is the ipv4 address of FreeSWITCH
	 * 
	 * @return freeSWITCHIPv4
	 */
	public String getFreeSwitchIPv4() {
		return freeSwitchIPv4;
	}

	/**
	 * Sets the default ipv4 address of FreeSWITCH server
	 * 
	 * @param freeSWITCHIPv4
	 */
	public void setFreeSwitchIPv4(String freeSwitchIPv4) {
		this.freeSwitchIPv4 = freeSwitchIPv4;
	}

	/**
	 * @return the freeSwitchIPv6
	 */
	public String getFreeSwitchIPv6() {
		return freeSwitchIPv6;
	}

	/**
	 * @param freeSwitchIPv6
	 *            the freeSwitchIPv6 to set
	 */
	public void setFreeSwitchIPv6(String freeSwitchIPv6) {
		this.freeSwitchIPv6 = freeSwitchIPv6;
	}

	/**
	 * @return the eventDateGMT
	 */
	public String getEventDateGMT() {
		return eventDateGMT;
	}

	/**
	 * @param eventDateGMT
	 *            the eventDateGMT to set
	 */
	public void setEventDateGMT(String eventDateGMT) {
		this.eventDateGMT = eventDateGMT;
	}

	/**
	 * @return the eventDateTimestamp
	 */
	public String getEventDateTimestamp() {
		return eventDateTimestamp;
	}

	/**
	 * @param eventDateTimestamp
	 *            the eventDateTimestamp to set
	 */
	public void setEventDateTimestamp(String eventDateTimestamp) {
		this.eventDateTimestamp = eventDateTimestamp;
	}

	/**
	 * @return the channelState
	 */
	public ChannelState getChannelState() {
		return channelState;
	}

	/**
	 * @param channelState
	 *            the channelState to set
	 */
	public void setChannelState(ChannelState channelState) {
		this.channelState = channelState;
	}

	/**
	 * @return the channelCallState
	 */
	public ChannelCallState getChannelCallState() {
		return channelCallState;
	}

	/**
	 * @param channelCallState
	 *            the channelCallState to set
	 */
	public void setChannelCallState(ChannelCallState channelCallState) {
		this.channelCallState = channelCallState;
	}

	/**
	 * @return the channelStateNumber
	 */
	public Integer getChannelStateNumber() {
		return channelStateNumber;
	}

	/**
	 * @param channelStateNumber
	 *            the channelStateNumber to set
	 */
	public void setChannelStateNumber(Integer channelStateNumber) {
		this.channelStateNumber = channelStateNumber;
	}

	/**
	 * @return the channelName
	 */
	public String getChannelName() {
		return channelName;
	}

	/**
	 * @param channelName
	 *            the channelName to set
	 */
	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}

	/**
	 * @return the uniqueID
	 */
	public String getUniqueID() {
		return uniqueID;
	}

	/**
	 * @param uniqueID
	 *            the uniqueID to set
	 */
	public void setUniqueID(String uniqueID) {
		this.uniqueID = uniqueID;
	}

	/**
	 * @return the callDirection
	 */
	public String getCallDirection() {
		return callDirection;
	}

	/**
	 * @param callDirection
	 *            the callDirection to set
	 */
	public void setCallDirection(String callDirection) {
		this.callDirection = callDirection;
	}

	/**
	 * @return the presenceCallDirection
	 */
	public String getPresenceCallDirection() {
		return presenceCallDirection;
	}

	/**
	 * @param presenceCallDirection
	 *            the presenceCallDirection to set
	 */
	public void setPresenceCallDirection(String presenceCallDirection) {
		this.presenceCallDirection = presenceCallDirection;
	}

	/**
	 * @return the channelPresenceID
	 */
	public String getChannelPresenceID() {
		return channelPresenceID;
	}

	/**
	 * @param channelPresenceID
	 *            the channelPresenceID to set
	 */
	public void setChannelPresenceID(String channelPresenceID) {
		this.channelPresenceID = channelPresenceID;
	}

	/**
	 * @return the channelCallUUID
	 */
	public String getChannelCallUUID() {
		return channelCallUUID;
	}

	/**
	 * @param channelCallUUID
	 *            the channelCallUUID to set
	 */
	public void setChannelCallUUID(String channelCallUUID) {
		this.channelCallUUID = channelCallUUID;
	}

	/**
	 * @return the answerState
	 */
	public ChannelCallState getAnswerState() {
		return answerState;
	}

	/**
	 * @param answerState
	 *            the answerState to set
	 */
	public void setAnswerState(ChannelCallState answerState) {
		this.answerState = answerState;
	}

	/**
	 * @return the channelReadCodecName
	 */
	public String getChannelReadCodecName() {
		return channelReadCodecName;
	}

	/**
	 * @param channelReadCodecName
	 *            the channelReadCodecName to set
	 */
	public void setChannelReadCodecName(String channelReadCodecName) {
		this.channelReadCodecName = channelReadCodecName;
	}

	/**
	 * @return the channelReadCodecRate
	 */
	public Integer getChannelReadCodecRate() {
		return channelReadCodecRate;
	}

	/**
	 * @param channelReadCodecRate
	 *            the channelReadCodecRate to set
	 */
	public void setChannelReadCodecRate(Integer channelReadCodecRate) {
		this.channelReadCodecRate = channelReadCodecRate;
	}

	/**
	 * @return the channelReadCodecBitRate
	 */
	public Integer getChannelReadCodecBitRate() {
		return channelReadCodecBitRate;
	}

	/**
	 * @param channelReadCodecBitRate
	 *            the channelReadCodecBitRate to set
	 */
	public void setChannelReadCodecBitRate(Integer channelReadCodecBitRate) {
		this.channelReadCodecBitRate = channelReadCodecBitRate;
	}

	/**
	 * @return the channelWriteCodecName
	 */
	public String getChannelWriteCodecName() {
		return channelWriteCodecName;
	}

	/**
	 * @param channelWriteCodecName
	 *            the channelWriteCodecName to set
	 */
	public void setChannelWriteCodecName(String channelWriteCodecName) {
		this.channelWriteCodecName = channelWriteCodecName;
	}

	/**
	 * @return the channelWriteCodecRate
	 */
	public Integer getChannelWriteCodecRate() {
		return channelWriteCodecRate;
	}

	/**
	 * @param channelWriteCodecRate
	 *            the channelWriteCodecRate to set
	 */
	public void setChannelWriteCodecRate(Integer channelWriteCodecRate) {
		this.channelWriteCodecRate = channelWriteCodecRate;
	}

	/**
	 * @return the channelWriteCodecBitRate
	 */
	public Integer getChannelWriteCodecBitRate() {
		return channelWriteCodecBitRate;
	}

	/**
	 * @param channelWriteCodecBitRate
	 *            the channelWriteCodecBitRate to set
	 */
	public void setChannelWriteCodecBitRate(Integer channelWriteCodecBitRate) {
		this.channelWriteCodecBitRate = channelWriteCodecBitRate;
	}

	/**
	 * @return the callerDirection
	 */
	public String getCallerDirection() {
		return callerDirection;
	}

	/**
	 * @param callerDirection
	 *            the callerDirection to set
	 */
	public void setCallerDirection(String callerDirection) {
		this.callerDirection = callerDirection;
	}

	/**
	 * @return the callerCallerIDNumber
	 */
	public String getCallerCallerIDNumber() {
		return callerCallerIDNumber;
	}

	/**
	 * @param callerCallerIDNumber
	 *            the callerCallerIDNumber to set
	 */
	public void setCallerCallerIDNumber(String callerCallerIDNumber) {
		this.callerCallerIDNumber = callerCallerIDNumber;
	}

	/**
	 * @return the callerCalleeIDName
	 */
	public String getCallerCalleeIDName() {
		return callerCalleeIDName;
	}

	/**
	 * @param callerCalleeIDName
	 *            the callerCalleeIDName to set
	 */
	public void setCallerCalleeIDName(String callerCalleeIDName) {
		this.callerCalleeIDName = callerCalleeIDName;
	}

	/**
	 * @return the callerCalleeIDNumber
	 */
	public String getCallerCalleeIDNumber() {
		return callerCalleeIDNumber;
	}

	/**
	 * @param callerCalleeIDNumber
	 *            the callerCalleeIDNumber to set
	 */
	public void setCallerCalleeIDNumber(String callerCalleeIDNumber) {
		this.callerCalleeIDNumber = callerCalleeIDNumber;
	}

	/**
	 * @return the callerNetworkAddr
	 */
	public String getCallerNetworkAddr() {
		return callerNetworkAddr;
	}

	/**
	 * @param callerNetworkAddr
	 *            the callerNetworkAddr to set
	 */
	public void setCallerNetworkAddr(String callerNetworkAddr) {
		this.callerNetworkAddr = callerNetworkAddr;
	}

	/**
	 * @return the callerDestinationNumber
	 */
	public String getCallerDestinationNumber() {
		return callerDestinationNumber;
	}

	/**
	 * @param callerDestinationNumber
	 *            the callerDestinationNumber to set
	 */
	public void setCallerDestinationNumber(String callerDestinationNumber) {
		this.callerDestinationNumber = callerDestinationNumber;
	}

	/**
	 * @return the callerUniqueID
	 */
	public String getCallerUniqueID() {
		return callerUniqueID;
	}

	/**
	 * @param callerUniqueID
	 *            the callerUniqueID to set
	 */
	public void setCallerUniqueID(String callerUniqueID) {
		this.callerUniqueID = callerUniqueID;
	}

	/**
	 * @return the callerSource
	 */
	public String getCallerSource() {
		return callerSource;
	}

	/**
	 * @param callerSource
	 *            the callerSource to set
	 */
	public void setCallerSource(String callerSource) {
		this.callerSource = callerSource;
	}

	/**
	 * @return the callerContext
	 */
	public String getCallerContext() {
		return callerContext;
	}

	/**
	 * @param callerContext
	 *            the callerContext to set
	 */
	public void setCallerContext(String callerContext) {
		this.callerContext = callerContext;
	}

	/**
	 * @return the callerChannelName
	 */
	public String getCallerChannelName() {
		return callerChannelName;
	}

	/**
	 * @param callerChannelName
	 *            the callerChannelName to set
	 */
	public void setCallerChannelName(String callerChannelName) {
		this.callerChannelName = callerChannelName;
	}

	/**
	 * @return the callerProfileIndex
	 */
	public Integer getCallerProfileIndex() {
		return callerProfileIndex;
	}

	/**
	 * @param callerProfileIndex
	 *            the callerProfileIndex to set
	 */
	public void setCallerProfileIndex(Integer callerProfileIndex) {
		this.callerProfileIndex = callerProfileIndex;
	}

	/**
	 * @return the callerProfileCreatedTime
	 */
	public String getCallerProfileCreatedTime() {
		return callerProfileCreatedTime;
	}

	/**
	 * @param callerProfileCreatedTime
	 *            the callerProfileCreatedTime to set
	 */
	public void setCallerProfileCreatedTime(String callerProfileCreatedTime) {
		this.callerProfileCreatedTime = callerProfileCreatedTime;
	}

	/**
	 * @return the callerChannelCreatedTime
	 */
	public String getCallerChannelCreatedTime() {
		return callerChannelCreatedTime;
	}

	/**
	 * @param callerChannelCreatedTime
	 *            the callerChannelCreatedTime to set
	 */
	public void setCallerChannelCreatedTime(String callerChannelCreatedTime) {
		this.callerChannelCreatedTime = callerChannelCreatedTime;
	}

	/**
	 * @return the callerChannelAnsweredTime
	 */
	public String getCallerChannelAnsweredTime() {
		return callerChannelAnsweredTime;
	}

	/**
	 * @param callerChannelAnsweredTime
	 *            the callerChannelAnsweredTime to set
	 */
	public void setCallerChannelAnsweredTime(String callerChannelAnsweredTime) {
		this.callerChannelAnsweredTime = callerChannelAnsweredTime;
	}

	/**
	 * @return the callerChannelProgressTime
	 */
	public String getCallerChannelProgressTime() {
		return callerChannelProgressTime;
	}

	/**
	 * @param callerChannelProgressTime
	 *            the callerChannelProgressTime to set
	 */
	public void setCallerChannelProgressTime(String callerChannelProgressTime) {
		this.callerChannelProgressTime = callerChannelProgressTime;
	}

	/**
	 * @return the callerChannelProgressMediaTime
	 */
	public String getCallerChannelProgressMediaTime() {
		return callerChannelProgressMediaTime;
	}

	/**
	 * @param callerChannelProgressMediaTime
	 *            the callerChannelProgressMediaTime to set
	 */
	public void setCallerChannelProgressMediaTime(
			String callerChannelProgressMediaTime) {
		this.callerChannelProgressMediaTime = callerChannelProgressMediaTime;
	}

	/**
	 * @return the callerChannelHangupTime
	 */
	public String getCallerChannelHangupTime() {
		return callerChannelHangupTime;
	}

	/**
	 * @param callerChannelHangupTime
	 *            the callerChannelHangupTime to set
	 */
	public void setCallerChannelHangupTime(String callerChannelHangupTime) {
		this.callerChannelHangupTime = callerChannelHangupTime;
	}

	/**
	 * @return the callerChannelTransferTime
	 */
	public String getCallerChannelTransferTime() {
		return callerChannelTransferTime;
	}

	/**
	 * @param callerChannelTransferTime
	 *            the callerChannelTransferTime to set
	 */
	public void setCallerChannelTransferTime(String callerChannelTransferTime) {
		this.callerChannelTransferTime = callerChannelTransferTime;
	}

	/**
	 * @return the callerScreenBit
	 */
	public boolean isCallerScreenBit() {
		return callerScreenBit;
	}

	/**
	 * @param callerScreenBit
	 *            the callerScreenBit to set
	 */
	public void setCallerScreenBit(boolean callerScreenBit) {
		this.callerScreenBit = callerScreenBit;
	}

	/**
	 * @return the callerPrivacyHideName
	 */
	public boolean isCallerPrivacyHideName() {
		return callerPrivacyHideName;
	}

	/**
	 * @param callerPrivacyHideName
	 *            the callerPrivacyHideName to set
	 */
	public void setCallerPrivacyHideName(boolean callerPrivacyHideName) {
		this.callerPrivacyHideName = callerPrivacyHideName;
	}

	/**
	 * @return the callerPrivacyHideNumber
	 */
	public boolean isCallerPrivacyHideNumber() {
		return callerPrivacyHideNumber;
	}

	/**
	 * @param callerPrivacyHideNumber
	 *            the callerPrivacyHideNumber to set
	 */
	public void setCallerPrivacyHideNumber(boolean callerPrivacyHideNumber) {
		this.callerPrivacyHideNumber = callerPrivacyHideNumber;
	}

	private ChannelHandlerContext ctx;
	private Channel channel;

	public void setChannelHandlerContext(ChannelHandlerContext ctx) {
		this.ctx = ctx;
		this.setChannel(ctx.getChannel());
	}

	public ChannelHandlerContext getChannelHandlerContext() {
		return ctx;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public Channel getChannel() {
		return channel;
	}

}
